package com.woniuxy.third.controller;

import com.woniuxy.third.entity.Payments;
import com.woniuxy.third.result.ResponseResult;
import com.woniuxy.third.service.PaymentsService;
import com.woniuxy.third.utils.GetUserUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: yangtao
 * @date 2021/7/22 10:26
 * @Version 1.0
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Resource
    private PaymentsService paymentsService;

    @GetMapping("/findByUid")
    @ApiOperation(value = "查询支付信息", notes = "返回支付信息对象")
    public ResponseResult<Payments> findByUid(HttpServletRequest request){
        int uid = GetUserUtil.getUser(request).getId();
        Payments payments = paymentsService.findByUid(uid);
        if (payments != null) {
            return new ResponseResult<>(200, "查询成功", payments);
        }

        return new ResponseResult<>(500, "查询失败", new Payments().setPayment("支付宝").setPaynum("请填写支付账号").setCollnum("请填写收款账号"));
    }
}
